package sk.naive.talker.command;

import sk.naive.talker.*;
import sk.naive.talker.message.Category;
import sk.naive.talker.util.Buffer;

import java.rmi.RemoteException;
import java.util.Collection;

/**
 *
 * @author <a href="mailto:rytier@naive.deepblue.sk">Martin "Rytier" Kerni</a>
 * @version $Revision: 1.11 $ $Date: 2005/01/19 22:41:27 $
 */
public abstract class NonaddressedLocalMessageCommand extends NonaddressedMessageCommand {
	public final void exec()
		throws CommandException,
		RemoteException
	{
		Location loc = new LocationHelper(commandDispatcher).locationForUser(user);
		if (loc == null) {
			sendHelper().sendMessage(user, "message.noRoom");
		} else {
			super.exec();
		}
	}

	public Collection<User> getPossibleTargetUsers(User u) {
		return new LocationHelper(commandDispatcher).locationForUser(u).users();
	}

	public Buffer getBuffer(User u) throws CommandException {
		return new LocationHelper(commandDispatcher).locationBufferForUser(this);
	}

	protected String misusageWarning() {
		return "say.what";
	}

	protected Category getCategory() {
		return Category.SAY;
	}
}
